package org.jeecg.modules.param.member.controller;


import com.alibaba.fastjson.JSON;
import com.xkcoding.http.util.StringUtil;
import org.apache.commons.lang3.StringUtils;
import org.jeecg.common.constant.CommonConstant;
import org.jeecg.common.system.query.QueryGenerator;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.system.base.controller.JeecgController;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.util.PasswordUtil;
import org.jeecg.common.util.RedisUtil;
import org.jeecg.modules.common.service.CommonMethodService;
import org.jeecg.modules.constant.BikeConstant;
import org.jeecg.modules.param.charge.service.IBikeMemberUserChargeService;
import org.jeecg.modules.param.member.vo.MemberStatisticsReq;
import org.jeecg.modules.param.member.vo.MemberStatisticsRsp;
import org.jeecg.modules.param.member.vo.SysUserRes;
import org.jeecg.modules.param.member.vo.UserCard;
import org.jeecg.modules.param.sms.entity.BikeSysSmsCode;
import org.jeecg.modules.param.sms.service.IBikeSysSmsCodeService;
import org.jeecg.modules.system.allsmslog.entity.BikeSysSmsLog;
import org.jeecg.modules.system.allsmslog.service.BikeSysSmsLogService;
import org.jeecg.modules.system.upgrade.mapper.BikeUpgradeAppMapper;
import org.jeecg.modules.utils.BikeResult;
import org.jeecg.modules.utils.ExcelUtils;
import org.jeecg.modules.utils.RandomCodeUtils;
import org.jeecg.modules.utils.SMSDmeo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.web.servlet.ModelAndView;

import java.util.*;

import org.jeecg.common.util.oConvertUtils;
import org.jeecg.modules.param.member.entity.BikeMemberUserCard;
import org.jeecg.modules.param.member.entity.BikeMemberUser;
import org.jeecg.modules.param.member.service.IBikeMemberUserService;
import org.jeecg.modules.param.member.service.IBikeMemberUserCardService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.apache.shiro.SecurityUtils;
import org.jeecg.common.system.vo.LoginUser;
import org.jeecgframework.poi.excel.ExcelImportUtil;
import org.jeecgframework.poi.excel.def.NormalExcelConstants;
import org.jeecgframework.poi.excel.entity.ExportParams;
import org.jeecgframework.poi.excel.entity.ImportParams;
import org.jeecgframework.poi.excel.view.JeecgEntityExcelView;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import java.io.IOException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.stream.Collectors;

/**
 * @Description: 会员用户管理
 * @Author: 月月鸟
 * @Date:   2021-05-25
 * @Version: V1.0
 */
@Api(tags="会员用户管理")
@RestController
@RequestMapping("/member/bikeMemberUser")
@Slf4j
public class BikeMemberUserController extends JeecgController<BikeMemberUser, IBikeMemberUserService> {

	@Autowired
	private IBikeMemberUserService bikeMemberUserService;

	@Autowired
	private IBikeMemberUserCardService bikeMemberUserCardService;

	@Autowired
	private IBikeSysSmsCodeService iBikeSysSmsCodeService;
	@Autowired
	private CommonMethodService commonMethodService;
	@Autowired
	private RedisUtil redisUtil;

	@Autowired
	private BikeSysSmsLogService bikeSysSmsLogService;
	@Autowired
	private IBikeMemberUserChargeService iBikeMemberUserChargeService;

	/*---------------------------------主表处理-begin-------------------------------------*/

	/**
	 * 分页列表查询
	 * @param
	 * @param pageNo
	 * @param pageSize
	 * @param req
	 * @return
	 */
	@ApiOperation(value="会员用户管理-分页列表查询", notes="会员用户管理-分页列表查询")
	@GetMapping(value = "/list")
	public Result<?> queryPageList(UserCard userCard,
								   @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
								   @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
								   HttpServletRequest req) {
		return Result.OK(bikeMemberUserService.pageList(pageNo, pageSize, userCard));
	}
	/**
	 * 查询详情
	 * @param
	 * @param pageNo
	 * @param pageSize
	 * @param req
	 * @return
	 */
	@ApiOperation(value="会员用户管理-查询详情", notes="会员用户管理-查询详情")
	@GetMapping(value = "/listById")
	public Result<?> queryPageListById(UserCard userCard,
								   @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
								   @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
								   HttpServletRequest req) {

		////转换读取获取到的cardCode
		//if (StringUtils.isNotEmpty(userCard.getCardCode())){
		//	//16数据转10
		//	String Code = EstUtils.hexToAscii(userCard.getCardCode());
		//	//限制截取长度，避免空
		//	userCard.setCardCode(Code.substring(0, 15));
		//}
		List<UserCard> userCards = bikeMemberUserService.queryPageListById(pageNo, pageSize, userCard);
		return Result.OK(userCards);
	}
	/**
	 * 会员借车次数统计
	 * @param memberStatisticsReq
	 * @param pageNo
	 * @param pageSize
	 * @param req
	 * @return
	 */
	@ApiOperation(value="数据分析-会员借车次数统计", notes="数据分析-会员借车次数统计")
	@GetMapping(value = "/statistics")
	public Result<?> statistics(MemberStatisticsReq memberStatisticsReq,
								@RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
								@RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
								HttpServletRequest req) {
		QueryWrapper<BikeMemberUser> wrapper = new QueryWrapper<>();
		if (StringUtils.isNotEmpty(memberStatisticsReq.getUserCode())){
			wrapper.like("code",memberStatisticsReq.getUserCode());
		}
		Page<BikeMemberUser> page = bikeMemberUserService.page(new Page<>(pageNo, pageSize), wrapper);
		List<MemberStatisticsRsp> memberStatisticsRsps =bikeMemberUserService.statistics(page.getRecords(),memberStatisticsReq);
		Page<MemberStatisticsRsp> memberStatisticsRspPage = new Page<>();
		memberStatisticsRspPage.setRecords(memberStatisticsRsps);
		memberStatisticsRspPage.setTotal(memberStatisticsRsps.size());
		return Result.OK(memberStatisticsRspPage);
	}
	/**
	 会员借车次数统计 导出
	 * @return
	 */
	@ApiOperation(value="会员借车次数统计-导出", notes="会员借车次数统计-导出")
	@GetMapping(value = "/exportXlsStatistics")
	public ModelAndView exportXlsStatistics( MemberStatisticsReq memberStatisticsReq,
										   HttpServletRequest req) {
		QueryWrapper<BikeMemberUser> wrapper = new QueryWrapper<>();
		if (StringUtils.isNotEmpty(memberStatisticsReq.getUserCode())){
			wrapper.like("code",memberStatisticsReq.getUserCode());
		}
		List<BikeMemberUser> list = bikeMemberUserService.list(wrapper);
		List<MemberStatisticsRsp> memberStatisticsRsps =bikeMemberUserService.statistics(list,memberStatisticsReq);

		return ExcelUtils.exportXls(req,memberStatisticsRsps,MemberStatisticsRsp.class,"会员借车次数统计表");
	}
	/**
	 * 查询管理员
	 * @param sysUserRes appType 1，保洁，2，调度，3，维修
	 * @param pageNo
	 * @param pageSize
	 * @param req
	 * @return
	 */
	@ApiOperation(value="根据运维app权限-查询管理会员", notes="根据运维app权限-查询管理会员")
	@GetMapping(value = "/listAdmin")
	public Result<?> listAdmin(SysUserRes sysUserRes,
							   @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
							   @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
							   HttpServletRequest req) {
		return bikeMemberUserService.listAdmin(sysUserRes,pageNo,pageSize);
	}

	/**
	 *   添加
	 * @param bikeMemberUser
	 * @return
	 */
	@AutoLog(value = "会员用户管理-新增")
	@ApiOperation(value="会员用户管理-注册", notes="会员用户管理-注册")
	@PostMapping(value = "/add")
	public Result<?> add(@RequestBody BikeMemberUser bikeMemberUser) {
		String uuid = RandomCodeUtils.getUUID();
		//判断验证码
		if (StringUtils.isNotEmpty(bikeMemberUser.getSmsCode())){
			if (!redisUtil.get(bikeMemberUser.getPhone()).equals(bikeMemberUser.getSmsCode())){
				return Result.error("验证码错误!");
			}
		}else {
			return Result.error("请输入验证码");
		}
		QueryWrapper<BikeMemberUser> wrapper = new QueryWrapper<>();
		wrapper.eq("code",bikeMemberUser.getPhone());
		wrapper.ne("status","4");
		int count = bikeMemberUserService.count(wrapper);
		//通过手机号判断是否存在
		if (count==0){
			//手机号为账号
			bikeMemberUser.setCode(bikeMemberUser.getPhone());
		}else {
			return Result.error("手机号已注册！");
		}
		int idCard = bikeMemberUserService.count(new QueryWrapper<BikeMemberUser>().eq("id_card", bikeMemberUser.getIdCard()));
		if (idCard!=0){
			return Result.error("该身份证已注册！");
		}
		//后台添加默认 2  ic卡用户
		bikeMemberUser.setRegisterType("2");
		//设置默认密码
		String salt = oConvertUtils.randomGen(8);
		bikeMemberUser.setPassword(PasswordUtil.encrypt(bikeMemberUser.getCode(), "123456", salt));
		//身份证姓名必填，所以已实名
		bikeMemberUser.setIsCertification(BikeConstant.y_n_yes);
		bikeMemberUser.setSalt(salt);
		bikeMemberUserService.save(bikeMemberUser);
		//// TODO: 2021/5/26 后面要改成修改
		//bikeMemberUserCardService.setUserCard(bikeMemberUser);
		redisUtil.del(bikeMemberUser.getPhone());
		//调整所有用户身份证后1位x转为X
		ExecutorService fixedThreadPool = Executors.newCachedThreadPool();
		fixedThreadPool.execute(new Runnable() {
			@Override
			public void run() {
				try {
					Thread.sleep(1000);
					commonMethodService.updateIdCard();
					Thread.interrupted();
				} catch (InterruptedException e) {
					e.printStackTrace();
				}finally {
					Thread.interrupted();
				}
			}
		});
		return Result.OK("添加成功！");
	}

	/**
	 *  1 为编辑   2 为充值   3为黑名单 4 为注销  5激活用户
	 * @param bikeMemberUser  methodType 1 为编辑   2 为充值   3为黑名单 4 为注销 5 5激活用户
	 * @return
	 */
	@AutoLog(value = "会员用户管理-1编辑-2充值-3添加黑名单-5激活用户",operateType = 3)
	@ApiOperation(value="1编辑-2充值-3黑名单-4注销-5激活用户", notes="1编辑-2充值-3黑名单-4注销-5激活用户")
	@PutMapping(value = "/edit")
	public Result<?> edit(@RequestBody BikeMemberUser bikeMemberUser) {
		//新对象
		BikeMemberUser memberUser = new BikeMemberUser();
		memberUser.setId(bikeMemberUser.getId());
		//编辑会员信息
		if (bikeMemberUser.getMethodType().equals("1")){
			if (StringUtils.isNotEmpty(bikeMemberUser.getIdCard())){
				int idCard = bikeMemberUserService.count(new QueryWrapper<BikeMemberUser>()
						.ne("id",bikeMemberUser.getId())
						.eq("id_card", bikeMemberUser.getIdCard()));
				if (idCard!=0){
					return Result.error("该身份证已注册！");
				}
				bikeMemberUser.setIsCertification(BikeConstant.y_n_yes);
			}
			Result<?> result = bikeMemberUserService.editUser(bikeMemberUser);
			//调整所有用户身份证后1位x转为X
			ExecutorService fixedThreadPool = Executors.newCachedThreadPool();
			fixedThreadPool.execute(new Runnable() {
				@Override
				public void run() {
					try {
						Thread.sleep(1000);
						commonMethodService.updateIdCard();
						Thread.interrupted();
					} catch (InterruptedException e) {
						e.printStackTrace();
					}finally {
						Thread.interrupted();
					}
				}
			});
			return result;
		}
		//充值
		if (bikeMemberUser.getMethodType().equals("2")){
			//校验是否可以充值
			String s = bikeMemberUserService.checkRecharge(bikeMemberUser);
			if (!s.equals(BikeConstant.y_n_yes)){
				return Result.error(s);
			}

			if (bikeMemberUser.getPay()!=null){
				memberUser.setBalance(bikeMemberUser.getBalance().add(bikeMemberUser.getPay()));
			}
			bikeMemberUserService.updateById(memberUser);
			iBikeMemberUserChargeService.saveCharge(bikeMemberUser);
			////校验是否有未支付订单，有完结，抵消充值金额；
			//bikeMemberUserService.checkPayOrderByUserId(bikeMemberUser.getId());
			return Result.OK("充值成功!");
		}
		//黑名单
		if (bikeMemberUser.getMethodType().equals("3")){
			memberUser.setStatus(BikeConstant.member_status_blacklist);

			bikeMemberUserService.updateById(memberUser);
			return Result.OK("添加成功!");
		}
		//注销
		if (bikeMemberUser.getMethodType().equals("4")){
			//如果有余额，全部现金退款
			return bikeMemberUserService.refund(memberUser);
		}
		//激活用户 注销状态改为正常
		if (bikeMemberUser.getMethodType().equals("5")){
			memberUser.setStatus(BikeConstant.member_status_normal);
			return bikeMemberUserService.activate(memberUser);
		}
		return Result.error("请传入编辑类型！");
	}

	/**
	 * 校验手机号是否注册
	 * @param phone
	 * @return
	 */
	@ApiOperation(value="换绑手机号，校验手机号是否注册", notes="换绑手机号，传id和phone")
	@GetMapping(value = "/checkPhone")
	public BikeResult checkPhone(@RequestParam(value = "phone")String phone) {
		boolean b = bikeMemberUserService.checkPhone(phone);
		if (b){
			return BikeResult.ok("0","成功",null);
		}else {
			return BikeResult.ok("1","手机号已注册",null);
		}
	}

	/**
	 * 换绑手机号
	 * @param bikeMemberUser  传 id 和phone
	 * @return
	 */
	@AutoLog(value = "会员用户管理-换绑手机号",operateType = 3)
	@ApiOperation(value="换绑手机号，传id和phone", notes="换绑手机号，传id和phone")
	@PutMapping(value = "/changePhone")
	public Result<?> changePhone(@RequestBody BikeMemberUser bikeMemberUser) {
		return bikeMemberUserService.changePhone(bikeMemberUser);
	}

	@ApiOperation(value="会员用户管理-发送验证码1注册4验证手机", notes="会员用户管理-发送验证码")
	@GetMapping(value = "/smsCode")
	public Result<?> smsCode(String phone,String type) {
		if (StringUtil.isEmpty(phone) || phone.length() != 11){
			return Result.error("无效手机号");
		}
		LoginUser principal = (LoginUser) SecurityUtils.getSubject().getPrincipal();

		// 生成验证码
		StringBuilder code = new StringBuilder();
		for (int i = 0; i < 6; i++) {
			code.append(String.valueOf((int) Math.floor(Math.random() * 9 + 1)));
		}

		// 发送验证码
		String result = SMSDmeo.send(phone, code.toString());
		Map resultMap= JSON.parseObject(result, Map.class);
		String resultCode= resultMap.get("status").toString();

		// 发送结果
		if(resultCode.equals("0")){
			// TODO: 2021/5/26 会员短信有效600秒写死
			redisUtil.set(phone, code.toString(),600);
			//短信记录存入库
			BikeSysSmsCode bikeSysSmsCode = new BikeSysSmsCode();
			bikeSysSmsCode.setMobile(phone);
			bikeSysSmsCode.setType(type);
			bikeSysSmsCode.setRequestTime(new Date());
			bikeSysSmsCode.setExpiredTime(600);
			bikeSysSmsCode.setType(type);
			//发送短信记录表
			BikeSysSmsLog bikeSysSmsLog = new BikeSysSmsLog();
			bikeSysSmsLog.setContent("验证码" + code + "，用于注册/登录，10分钟内有效。验证码提供给他人可能导致账号被盗，请勿泄漏，谨防被骗。");
			bikeSysSmsLog.setMobile(phone);
			if (type.equals("5")){
				bikeSysSmsLog.setType("7");
			}else if (type.equals("1")){
				bikeSysSmsLog.setType("6");
			}
			bikeSysSmsLog.setCreateBy(principal.getRealname());
			bikeSysSmsLogService.add(bikeSysSmsLog);
			return Result.OK("验证码发送成功！");
		} else {
			return Result.error("验证码发送失败！");
		}
	}

	/**
	 * 通过id删除
	 * @param id
	 * @return
	 * 注销状态才能删除
	 */
	@AutoLog(value = "会员用户管理-通过id删除")
	@ApiOperation(value="会员用户管理-通过id删除", notes="会员用户管理-通过id删除")
	@DeleteMapping(value = "/delete")
	public Result<?> delete(@RequestParam(name="id",required=true) String id) {

		return bikeMemberUserService.delete(id);
	}

	/**
	 * 批量删除
	 * @param ids
	 * @return
	 */
	@AutoLog(value = "会员用户管理-批量删除")
	@ApiOperation(value="会员用户管理-批量删除", notes="会员用户管理-批量删除")
	@DeleteMapping(value = "/deleteBatch")
	public Result<?> deleteBatch(@RequestParam(name="ids",required=true) String ids) {
		this.bikeMemberUserService.delBatchMain(Arrays.asList(ids.split(",")));
		return Result.OK("批量删除成功!");
	}

	/**
	 * 导出
	 * 条件
	 * @return
	 */
	@ApiOperation(value="会员用户管理-导出", notes="会员用户管理-导出")
	@GetMapping(value = "/exportXls")
	public ModelAndView exportUserCardXls( UserCard userCard,
										   HttpServletRequest req) {
		return ExcelUtils.exportXls(req,bikeMemberUserService.needList(userCard),UserCard.class,"会员信息IC卡管理表");
	}
	///**
	// * 导出
	// * @return
	// */
	//@RequestMapping(value = "/exportXls")
	//public ModelAndView exportXls(HttpServletRequest request, BikeMemberUser bikeMemberUser) {
	//	return super.exportXls(request, bikeMemberUser, BikeMemberUser.class, "会员用户管理");
	//}


	/**
	 * 导入
	 * @return
	 */
	@RequestMapping(value = "/importExcel", method = RequestMethod.POST)
	public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
		return super.importExcel(request, response, BikeMemberUser.class);
	}
	/*---------------------------------主表处理-end-------------------------------------*/


	/*--------------------------------子表处理-IC卡管理-begin----------------------------------------------*/
	/**
	 * 通过主表ID查询
	 * @return
	 */
	@ApiOperation(value="IC卡管理-通过主表ID查询", notes="IC卡管理-通过主表ID查询")
	@GetMapping(value = "/listBikeMemberUserCardByMainId")
	public Result<?> listBikeMemberUserCardByMainId(BikeMemberUserCard bikeMemberUserCard,
													@RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
													@RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
													HttpServletRequest req) {
		QueryWrapper<BikeMemberUserCard> queryWrapper = QueryGenerator.initQueryWrapper(bikeMemberUserCard, req.getParameterMap());
		Page<BikeMemberUserCard> page = new Page<BikeMemberUserCard>(pageNo, pageSize);
		IPage<BikeMemberUserCard> pageList = bikeMemberUserCardService.page(page, queryWrapper);
		return Result.OK(pageList);
	}

	/**
	 * 添加
	 * @param bikeMemberUserCard
	 * @return
	 */
	@AutoLog(value = "IC卡管理-添加")
	@ApiOperation(value="IC卡管理-添加", notes="IC卡管理-添加")
	@PostMapping(value = "/addBikeMemberUserCard")
	public Result<?> addBikeMemberUserCard(@RequestBody BikeMemberUserCard bikeMemberUserCard) {
		bikeMemberUserCardService.save(bikeMemberUserCard);
		return Result.OK("添加成功！");
	}


	/**
	 *
	 * @param bikeMemberUserCard
	 *
	 * @return
	 */
	@AutoLog(value = "IC卡管理-1换卡-2发卡-3挂失-4退卡-5解挂失-6退卡",operateType = 3)
	@ApiOperation(value="IC卡管理-1换卡-2发卡-3挂失-4退卡-5解挂失-6退卡", notes="IC卡管理-1换卡-2发卡-3挂失-4退卡-5解挂失-6退卡")
	@PutMapping(value = "/editBikeMemberUserCard")
	public Result<?> editBikeMemberUserCard(@RequestBody BikeMemberUserCard bikeMemberUserCard) {

		if (bikeMemberUserCard.getUserId()==null){
			return Result.error("请选择操作对象！");
		}else {
			String methodType = bikeMemberUserCard.getMethodType();
			//换卡退卡判断
			if(methodType.equals("1")||methodType.equals("6")){
				//判断条件是否符合
				String condition = bikeMemberUserCardService.condition(bikeMemberUserCard);
				if (condition.equals(BikeConstant.y_n_no)){
					return Result.error("有未支付订单");
				}
			}

			//校验状态
			String yn = bikeMemberUserService.checkStatus(bikeMemberUserCard.getUserId());
			if (!yn.equals(BikeConstant.y_n_yes)){
				return Result.error(yn);
			}
			BikeMemberUserCard memberUserCard = new BikeMemberUserCard();
			memberUserCard.setId(bikeMemberUserCard.getId());
			//判断换卡
			if (bikeMemberUserCard.getMethodType().equals("1")){
				return bikeMemberUserCardService.changeCard(bikeMemberUserCard);

			}
			//发卡
			if (bikeMemberUserCard.getMethodType().equals("2")){
				return 	bikeMemberUserCardService.issuance(bikeMemberUserCard);
			}
			//挂失
			if (bikeMemberUserCard.getMethodType().equals("3")){
				return bikeMemberUserCardService.updateByUserId(bikeMemberUserCard.getUserId(),bikeMemberUserCard.getMethodType());
			}
			//解挂失
			if (bikeMemberUserCard.getMethodType().equals("5")){
				return bikeMemberUserCardService.updateByUserId(bikeMemberUserCard.getUserId(),bikeMemberUserCard.getMethodType());
			}
			//退卡
			if (bikeMemberUserCard.getMethodType().equals("6")){
				if (bikeMemberUserCard.getId()==null){
					return Result.error("用户没有卡");
				}
				bikeMemberUserCardService.returnTheCard(bikeMemberUserCard);
				return Result.OK("退卡成功");
			}
			return Result.error("请选择状态");
		}
	}


	/**
	 * 检验免卡费
	 * @param id)
	 * @return  true false
	 */
	@ApiOperation(value="IC卡管理-检验免卡费", notes="IC卡管理-检验免卡费")
	@DeleteMapping(value = "/checkUserCardFree")
	public Result<?> checkUserCardFree(@RequestParam String id) {
		BikeMemberUserCard userCard = new BikeMemberUserCard();
		userCard.setUserId(id);
		boolean yn = bikeMemberUserCardService.checkUserCardFree(userCard);
		return Result.OK(yn);
	}
	/**
	 * 通过id删除
	 * @param id
	 * @return
	 */
	@AutoLog(value = "IC卡管理-通过id删除")
	@ApiOperation(value="IC卡管理-通过id删除", notes="IC卡管理-通过id删除")
	@DeleteMapping(value = "/deleteBikeMemberUserCard")
	public Result<?> deleteBikeMemberUserCard(@RequestParam(name="id",required=true) String id) {
		bikeMemberUserCardService.removeById(id);
		return Result.OK("删除成功!");
	}

	/**
	 * 批量删除
	 * @param ids
	 * @return
	 */
	@AutoLog(value = "IC卡管理-批量删除")
	@ApiOperation(value="IC卡管理-批量删除", notes="IC卡管理-批量删除")
	@DeleteMapping(value = "/deleteBatchBikeMemberUserCard")
	public Result<?> deleteBatchBikeMemberUserCard(@RequestParam(name="ids",required=true) String ids) {
		this.bikeMemberUserCardService.removeByIds(Arrays.asList(ids.split(",")));
		return Result.OK("批量删除成功!");
	}

	/**
	 * 导出
	 * @return
	 */
	@RequestMapping(value = "/exportBikeMemberUserCard")
	public ModelAndView exportBikeMemberUserCard(HttpServletRequest request, BikeMemberUserCard bikeMemberUserCard) {
		// Step.1 组装查询条件
		QueryWrapper<BikeMemberUserCard> queryWrapper = QueryGenerator.initQueryWrapper(bikeMemberUserCard, request.getParameterMap());
		LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();

		// Step.2 获取导出数据
		List<BikeMemberUserCard> pageList = bikeMemberUserCardService.list(queryWrapper);
		List<BikeMemberUserCard> exportList = null;

		// 过滤选中数据
		String selections = request.getParameter("selections");
		if (oConvertUtils.isNotEmpty(selections)) {
			List<String> selectionList = Arrays.asList(selections.split(","));
			exportList = pageList.stream().filter(item -> selectionList.contains(item.getId())).collect(Collectors.toList());
		} else {
			exportList = pageList;
		}

		// Step.3 AutoPoi 导出Excel
		ModelAndView mv = new ModelAndView(new JeecgEntityExcelView());
		mv.addObject(NormalExcelConstants.FILE_NAME, "IC卡管理"); //此处设置的filename无效 ,前端会重更新设置一下
		mv.addObject(NormalExcelConstants.CLASS, BikeMemberUserCard.class);
		mv.addObject(NormalExcelConstants.PARAMS, new ExportParams("IC卡管理报表", "导出人:" + sysUser.getRealname(), "IC卡管理"));
		mv.addObject(NormalExcelConstants.DATA_LIST, exportList);
		return mv;
	}

	/**
	 * 导入
	 * @return
	 */
	@RequestMapping(value = "/importBikeMemberUserCard/{mainId}")
	public Result<?> importBikeMemberUserCard(HttpServletRequest request, HttpServletResponse response, @PathVariable("mainId") String mainId) {
		MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
		Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
		for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
			MultipartFile file = entity.getValue();// 获取上传文件对象
			ImportParams params = new ImportParams();
			params.setTitleRows(2);
			params.setHeadRows(1);
			params.setNeedSave(true);
			try {
				List<BikeMemberUserCard> list = ExcelImportUtil.importExcel(file.getInputStream(), BikeMemberUserCard.class, params);
				for (BikeMemberUserCard temp : list) {
					temp.setUserId(mainId);
				}
				long start = System.currentTimeMillis();
				bikeMemberUserCardService.saveBatch(list);
				log.info("消耗时间" + (System.currentTimeMillis() - start) + "毫秒");
				return Result.OK("文件导入成功！数据行数：" + list.size());
			} catch (Exception e) {
				log.error(e.getMessage(), e);
				return Result.error("文件导入失败:" + e.getMessage());
			} finally {
				try {
					file.getInputStream().close();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
		}
		return Result.error("文件导入失败！");
	}

	/*--------------------------------子表处理-IC卡管理-end----------------------------------------------*/




}
